package com.lz.football.module.main.view
{
	import com.common.stdlib.DateUtil;
	import com.common.utils.SharedEnterFrame;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.MainEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.base.IComponent;
	
	import common.BaseView.DisplayMouseEventManager;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.Alert;
	import lz.controls.LButton;
	
	/**
	 *顶上面板 
	 * @author lake
	 * 
	 */	
	public class TopPanel extends Sprite implements IComponent
	{
		/**
		 *皮肤 
		 */		
		public var symbolSkin			:MovieClip;
		/**
		 *vip 
		 */		
		public static var vipBtn		:SimpleButton;
		/**
		 * 七日造星
		 */		
		public static var starBtn		:SimpleButton;
		/**
		 * 活跃度
		 */		
		public static var livelyBtn	:SimpleButton;
		/**
		 * 冲级
		 */		
		public static var levelBtn		:SimpleButton;
		/**
		 *签到 
		 */		
		public static var signBtn		:SimpleButton;
		/**
		 *国家挑战赛按钮 
		 */		
		public static var competeBtn 	:SimpleButton;
		/**
		 *首充礼包 
		 */		
		public var firstChargeBtn 		:SimpleButton;
		/**
		 *黄钻特权 
		 */		
		public var qzoneBtn				:SimpleButton;
		/**
		 *单日充值 
		 */		
		public var dayChargeBtn			:SimpleButton;
		/**
		 *圣诞活动 
		 */		
		public var christmasBtn			:SimpleButton;
		/**
		 *暴走按钮 
		 */		
		public var lzTeamBtn			:SimpleButton;
		/**
		 *竞猜 
		 */		
		public var guessBtn				:SimpleButton;
		/**
		 * 荣誉堂
		 */		
		public var honorBtn				:SimpleButton;
		/**
		 * 12宫按钮 
		 */		
		public var palaceBtn			:SimpleButton;
		/**
		 *节日礼包 
		 */		
		public var giftBtn				:SimpleButton;
		/**
		 * 激活码
		 */		
		public var cdkeyBtn				:SimpleButton;
		/**
		 * 打折
		 */		
		public var pOffBtn				:SimpleButton;
		/**
		 * 开服活动
		 */		
		public var openABtn				:SimpleButton;
		/**
		 *比赛大福利 
		 */		
		public var matchFBtn			:SimpleButton;
		/**
		 *累计消费 
		 */		
		public var lcusumeBtn			:SimpleButton;
		/**
		 *在线奖励按钮 
		 */		
		public var onLineBtn			:LButton;
		/**
		 *充值返利 
		 */		
		public var rechargeReBtn		:SimpleButton;
		/**
		 *按钮顺序  右左 
		 */		
		private static var btns		:Array;
		/**
		 *按钮顺序  右左 
		 */		
		private static var btns_1		:Array;
		/**
		 *对应初始坐标  右左 
		 */		
		private static var xyArr		:Array;
		/**
		 *对应初始坐标  右左 
		 */		
		private static var xyArr_1		:Array;
		
		/**
		 *在线奖励时间 
		 */
		private var _online:OnlineAward;
		
		public function TopPanel()
		{
			super();
		}
		/**
		 *初始化 
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			symbolSkin = view as MovieClip;
			signBtn = symbolSkin.signBtn;
			vipBtn = symbolSkin.vipBtn;
			starBtn = symbolSkin.starBtn;
			livelyBtn = symbolSkin.livelyBtn;
			levelBtn = symbolSkin.levelBtn;
			competeBtn = symbolSkin.competeBtn;
			firstChargeBtn = symbolSkin.firstChargeBtn;
			qzoneBtn = symbolSkin.qzoneBtn;
			dayChargeBtn = symbolSkin.dayChargeBtn;
			christmasBtn = symbolSkin.christmasBtn;
			lzTeamBtn = symbolSkin.lzTeamBtn;
			guessBtn = symbolSkin.guessBtn;
			honorBtn = symbolSkin.honorBtn;
			palaceBtn = symbolSkin.palaceBtn;
			giftBtn = symbolSkin.giftBtn;
			cdkeyBtn = symbolSkin.cdkeyBtn;
			pOffBtn = symbolSkin.pOffBtn;
			openABtn = symbolSkin.openABtn;
			matchFBtn = symbolSkin.matchFBtn;
			lcusumeBtn = symbolSkin.lcusumeBtn;
			onLineBtn = new LButton(symbolSkin.onLineBtn);
			onLineBtn.buttonMode = true;
			onLineBtn.enable = true;
			symbolSkin.onLineBtn.tMc.getBtn.visible = false;
			onLineBtn.visible = false;
			rechargeReBtn = symbolSkin.rechargeReBtn;
			var tipsInfo :String = "签到";
			DisplayMouseEventManager.instance.addTipsDisplay(signBtn,tipsInfo);
			tipsInfo = "VIP特权";
			DisplayMouseEventManager.instance.addTipsDisplay(vipBtn,tipsInfo);
			tipsInfo = "七步造星";
			DisplayMouseEventManager.instance.addTipsDisplay(starBtn,tipsInfo);
			tipsInfo = "活跃度";
			DisplayMouseEventManager.instance.addTipsDisplay(livelyBtn,tipsInfo);
			tipsInfo = "冲级活动";
			DisplayMouseEventManager.instance.addTipsDisplay(levelBtn,tipsInfo);
			tipsInfo = "国家对抗赛";
			DisplayMouseEventManager.instance.addTipsDisplay(competeBtn,tipsInfo);
			tipsInfo = "首充礼包";
			DisplayMouseEventManager.instance.addTipsDisplay(firstChargeBtn,tipsInfo);
			tipsInfo = "黄钻礼包";
			DisplayMouseEventManager.instance.addTipsDisplay(qzoneBtn,tipsInfo);
			tipsInfo = "充值活动";
			DisplayMouseEventManager.instance.addTipsDisplay(dayChargeBtn,tipsInfo);
			tipsInfo = "新春活动";
			DisplayMouseEventManager.instance.addTipsDisplay(christmasBtn,tipsInfo);
			tipsInfo = "球星贺新春";
			DisplayMouseEventManager.instance.addTipsDisplay(lzTeamBtn,tipsInfo);
			tipsInfo = "竞猜";
			DisplayMouseEventManager.instance.addTipsDisplay(guessBtn,tipsInfo);
			tipsInfo = "荣誉堂";
			DisplayMouseEventManager.instance.addTipsDisplay(honorBtn,tipsInfo);
			tipsInfo = "黄金12宫";
			DisplayMouseEventManager.instance.addTipsDisplay(palaceBtn,tipsInfo);
			tipsInfo = "节日礼包";
			DisplayMouseEventManager.instance.addTipsDisplay(giftBtn,tipsInfo);
			tipsInfo = "激活码兑换";
			DisplayMouseEventManager.instance.addTipsDisplay(cdkeyBtn,tipsInfo);
			tipsInfo = "开服活动";
			DisplayMouseEventManager.instance.addTipsDisplay(openABtn,tipsInfo);
			tipsInfo = "限时打折活动";
			DisplayMouseEventManager.instance.addTipsDisplay(pOffBtn,tipsInfo);
			tipsInfo = "比赛大福利";
			DisplayMouseEventManager.instance.addTipsDisplay(matchFBtn,tipsInfo);
			tipsInfo = "累计消费";
			DisplayMouseEventManager.instance.addTipsDisplay(lcusumeBtn,tipsInfo);
			tipsInfo = "充值返利";
			DisplayMouseEventManager.instance.addTipsDisplay(rechargeReBtn,tipsInfo);
			addEvtListener();
			if(GlobalDef.Platform_Code == 1)
			{
				
			}
			else
			{
				qzoneBtn.visible = false;
			}
			//ver
			lzTeamBtn.visible = false;
			//guessBtn.visible = false;
			//honorBtn.visible = false;
			//palaceBtn.visible = false;
			levelBtn.visible = false;
			livelyBtn.visible = false;
			giftBtn.visible = false;
			dayChargeBtn.visible = false;
			christmasBtn.visible = false;
			firstChargeBtn.visible = false;
			cdkeyBtn.visible = false;
			openABtn.visible = false;
			pOffBtn.visible = false;
			matchFBtn.visible = false;
			lcusumeBtn.visible = false;
			rechargeReBtn.visible = false;
			
			btns = [palaceBtn,honorBtn,guessBtn,starBtn,signBtn,competeBtn,qzoneBtn,livelyBtn,levelBtn,firstChargeBtn,giftBtn,dayChargeBtn,christmasBtn,lzTeamBtn];
			xyArr = [];
			xyArr.push({x:palaceBtn.x,y:palaceBtn.y});
			xyArr.push({x:honorBtn.x,y:honorBtn.y});
			xyArr.push({x:guessBtn.x,y:guessBtn.y});
			xyArr.push({x:starBtn.x,y:starBtn.y});
			xyArr.push({x:signBtn.x,y:signBtn.y});
			xyArr.push({x:competeBtn.x,y:competeBtn.y});
			xyArr.push({x:qzoneBtn.x,y:qzoneBtn.y});
			xyArr.push({x:livelyBtn.x,y:livelyBtn.y});
			xyArr.push({x:levelBtn.x,y:levelBtn.y});
			xyArr.push({x:firstChargeBtn.x,y:firstChargeBtn.y});
			xyArr.push({x:giftBtn.x,y:giftBtn.y});
			xyArr.push({x:dayChargeBtn.x,y:dayChargeBtn.y});
			xyArr.push({x:christmasBtn.x,y:christmasBtn.y});
			xyArr.push({x:lzTeamBtn.x,y:lzTeamBtn.y});
			
			btns_1 = [cdkeyBtn,pOffBtn,openABtn,matchFBtn,lcusumeBtn,rechargeReBtn,symbolSkin.onLineBtn];
			xyArr_1 = [];
			xyArr_1.push({x:cdkeyBtn.x,y:cdkeyBtn.y});
			xyArr_1.push({x:pOffBtn.x,y:pOffBtn.y});
			xyArr_1.push({x:openABtn.x,y:openABtn.y});
			xyArr_1.push({x:matchFBtn.x,y:matchFBtn.y});
			xyArr_1.push({x:lcusumeBtn.x,y:lcusumeBtn.y});
			xyArr_1.push({x:rechargeReBtn.x,y:rechargeReBtn.y});
			xyArr_1.push({x:symbolSkin.onLineBtn.x,y:symbolSkin.onLineBtn.y});
		}
		/**
		 *刷新按钮 
		 */		
		public function refreshBtns():void
		{
			onLineBtn.visible = true;
			var endDate 	:Date = new Date("2014/02/25");//结束日期
			var curDate 	:Date = new Date(AppData.getInstance().time * 1000);
			var xml:XML = ResourceManager.instance.getResource(ResourceConst.ACTIVITYTIME_XML);
			//限时打折
			var tstr1 :String = xml.timeLimit;
			tstr1 =tstr1.replace(/-/g,"/");
			tstr1 += " 23:59:59";
			var date1 :Date = new Date(tstr1);
			if(DateUtil.compareTwoDate(curDate,date1))
			{
				pOffBtn.visible = false;
			}
			else
			{
				pOffBtn.visible = true;
			}
			
			//充值回馈
			var tstr2 :String = xml.Topupfeedback;
			tstr2 =tstr2.replace(/-/g,"/");
			tstr2 += " 23:59:59";
			var date2 :Date = new Date(tstr2);
			if(DateUtil.compareTwoDate(curDate,date2))
			{
				dayChargeBtn.visible = false;
			}
			else
			{
				dayChargeBtn.visible = true;
			}
			
			//节日活动
			var tstr3 :String = xml.Festival;
			tstr3 =tstr3.replace(/-/g,"/");
			tstr3 += " 23:59:59";
			var date3 :Date = new Date(tstr3);
			if(DateUtil.compareTwoDate(curDate,date3))
			{
				giftBtn.visible = false;
			}
			else
			{
				giftBtn.visible = true;
			}
			//开服活动
			var tstr4 :String = xml.openServe;
			tstr4 =tstr4.replace(/-/g,"/");
			tstr4 += " 23:59:59";
			var date4 :Date = new Date(tstr4);
			if(DateUtil.compareTwoDate(curDate,date4))
			{
				openABtn.visible = false;
			}
			else
			{
				openABtn.visible = true;
			}
			//激活码
			var cdFlag :int = int(xml.isCdKey);
			if(cdFlag == 0)
			{
				cdkeyBtn.visible = false;
			}
			else
			{
				cdkeyBtn.visible = true;
			}
			
			
			//比赛福利
			var tstr8 :String = xml.activity8;
			tstr8 =tstr8.replace(/-/g,"/");
			tstr8 += " 23:59:59";
			var date8 :Date = new Date(tstr8);
			if(DateUtil.compareTwoDate(curDate,date8))
			{
				matchFBtn.visible = false;
			}
			else
			{
				matchFBtn.visible = true;
			}
			
			
			//累积消费
			var tstr9 :String = xml.activity9;
			tstr9 =tstr9.replace(/-/g,"/");
			tstr9 += " 23:59:59";
			var date9 :Date = new Date(tstr9);
			if(DateUtil.compareTwoDate(curDate,date9))
			{
				lcusumeBtn.visible = false;
			}
			else
			{
				lcusumeBtn.visible = true;
			}
			
			
			//充值返利
			var tstr10 :String = xml.active10;
			tstr10 =tstr10.replace(/-/g,"/");
			tstr10 += " 23:59:59";
			var date10 :Date = new Date(tstr10);
			if(DateUtil.compareTwoDate(curDate,date10))
			{
				rechargeReBtn.visible = false;
			}
			else
			{
				rechargeReBtn.visible = true;
			}
			
			
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			signBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			competeBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			livelyBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			starBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			levelBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			vipBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			firstChargeBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			qzoneBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			dayChargeBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			christmasBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			lzTeamBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			guessBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			honorBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			palaceBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			giftBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			cdkeyBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			openABtn.addEventListener(MouseEvent.CLICK,clickHandler);
			pOffBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			matchFBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			lcusumeBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			rechargeReBtn.addEventListener(MouseEvent.CLICK,clickHandler);
		}
		
		
		/**
		 *点击事件 
		 * @param e
		 * 
		 */		
		private function clickHandler(e :MouseEvent):void
		{
			switch(e.target)
			{
				case signBtn://签到
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.Open_Sign_View));
					break;
				}
				case competeBtn://国家挑战赛
				{
					if(AppData.getInstance().clubDatamanager.clubInfo.level <15)
					{
						Alert.showErrorTip("15级开启国家对抗赛");
						return;
					}
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_COMPETE_VIEW));
					break;
				}
				case livelyBtn://活跃度
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_LIVENESS));
					break;
				}
				case starBtn://起步造星
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_MAKESTAR));
					break;
				}
				case levelBtn://等级活动
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_LEVEL_ACTIVITY));
					break;
				}
				case vipBtn://vip
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_VIP_ACTIVITY));
					break;
				}
				case firstChargeBtn://首充礼包
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_FIRST_CHARGE));
					break;
				}
				case qzoneBtn://黄钻礼包
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_QZONE_VIEW));
					break;
				}
				case dayChargeBtn://充值活动
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_TOPUP_ACTIVE));
					break;
				}
				case christmasBtn://圣诞活动
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_CHRISTMAS_VIEW));
					break;
				}
				case lzTeamBtn://良众队
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_LZTEAM_VIEW));
					break;
				}
				case guessBtn://竞猜
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_GUESS_VIEW));
					break;
				}
				case honorBtn://荣誉堂
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_FAMEHALL_VIEW));
					break;
				}
				case palaceBtn://12宫
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_PALACE_VIEW));
					break;
				}
				case giftBtn://节日礼包
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_FESTIVAL_VIEW));
					break;
				}
				case cdkeyBtn://激活码
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_CDKEY_VIEW));
					break;
				}
				case openABtn://开服活动
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_OPENSERVE_VIEW));
					break;
				}
				case pOffBtn://限时打折 
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_TIMELIMIT_VIEW));
					break;
				}
				case matchFBtn://比赛福利
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_MATCHWELFARE_VIEW));
					break;
				}
				case lcusumeBtn:
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_ACCUMCON_VIEW));
					break;
				}
				case rechargeReBtn://充值返利
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.TOPUPREBATE_VIEW));
					break;
				}
					
			}
		}
		/**
		 *重设按钮位置 
		 */		
		public static function resizeBtnPos():void
		{
			var tbtn :DisplayObject;
			var j :int;
			var i :int;
			for(i = 0;i < btns.length;i++)
			{
				tbtn = btns[i];
				if(tbtn.visible)
				{
					tbtn.x = xyArr[j].x;
					j ++;
				}
			}
			j=0;;
			for(i = 0;i < btns_1.length;i++)
			{
				tbtn = btns_1[i];
				if(tbtn.visible)
				{
					tbtn.x = xyArr_1[j].x;
					j ++;
				}
			}
		}
		
		/**
		 *显示在线奖励时间 
		 * 
		 */
		public function showOnlineTime():void
		{
			if(_online == null)
			{
				_online = new OnlineAward();
				_online.initUI(symbolSkin.onLineBtn);
			}
			_online.setOnlinetime();
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
		}
		/**
		 *销毁 
		 * 
		 */
		public function destroyView():void
		{
		}
	}
}